package cn.itcast.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * 1,导入驱动java包
 * 创建libs,用来管理java包
 * 右键选择add as library
 * <p>
 * 2注册驱动
 * Class.forName("com.mysql.jdbc.Driver");
 * <p>
 * 3 获取数据库的对象
 * DriverManager.getConnection("jdbc:mysql://" + IPNAME + "/db3", USERNAME, PASSWORLD);
 * 4 定义SQl语句
 * String sql = "update account set salary = 500 where id = 1";
 * 5 获取执行sql的对象
 *  Statement statement = connection.createStatement();
 *  6执行SQL
 *  int count = statement.executeUpdate(sql);
 *  7 处理结果
 *  System.out.println(count);
 *
 * 8释放资源
 *         statement.close();
 *         connection.close();
 */
public class JdbcDome1 {

    private static final String IPNAME = "localhost:3306";
    private static final String USERNAME = "root";
    private static final String PASSWORLD = "root";

    public static void main(String[] args) throws Exception {
      //$  Class.forName("com.mysql.jdbc.Driver");

//        Connection connection = DriverManager.getConnection("jdbc:mysql://" + IPNAME + "/db3", USERNAME, PASSWORLD);
        Connection connection = DriverManager.getConnection("jdbc:mysql:///db3", USERNAME, PASSWORLD);

        String sql = "update account set salary = 2000 where id = 1";

        Statement statement = connection.createStatement();

        int count = statement.executeUpdate(sql);

        System.out.println(count);

        statement.close();
        connection.close();
    }
}
